<?php

namespace App\Http\Controllers\V1;

use App\Helpers\RestResponseFactory;
use App\Helpers\RestUtils;
use App\Http\Controllers\Controller;
use App\Models\Factory\FeedbackFactory;
use App\Models\Factory\ProductFactory;
use App\Models\Factory\SmsFactory;
use App\Models\Factory\UserFactory;
use Illuminate\Http\Request;

/**
 * Class WelfareController
 * @package App\Http\Controllers\V1
 * 意见反馈
 */
class FeedbackController extends Controller
{

    /**
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function opinion(Request $request)
    {
        //接收参数
        $data = $request->input();


        //拿到中间件里赋值的userId
        $user = $request -> get('user');

        //通过用户的uid向意见反馈里添加数据
        $opinion['content'] = $data['content'];
        $opinion['phone'] = $data['phone'];
        $opinion['uid'] = $user -> id;
        $opinion['create_time'] = date('Y-m-d H:i:s',time());
        $opinion = FeedbackFactory::addOpinionByUid($opinion);

        $re['data'] = $opinion ? '1' : '0';

        return RestResponseFactory::ok($re);

    }
}